import cv2 as cv
import numpy as np


def facedetect_demo(image):
    gray = cv.cvtColor(image,cv.COLOR_BGR2GRAY)
    gray = cv.equalizeHist(gray)
    facedetector = cv.CascadeClassifier('haarcascade_frontalface_default.xml')
    faces = facedetector.detectMultiScale(gray,1.3,2)
    for x,y,w,h in faces:
        cv.rectangle(image,(x,y),(x+w,y+h),(0,255,255),2)
    cv.imshow('face-detect',image)


src = cv.imread('lena.jpg',1)
cv.namedWindow('demo',cv.WINDOW_AUTOSIZE)
cv.imshow('demo',src)
facedetect_demo(src)
cv.waitKey(0)
cv.destroyAllWindows()